package cst.neu.yuejian_31.model;

import cst.neu.yuejian_31.bean.AddMasterCommentBean;
import cst.neu.yuejian_31.iface.AddMasterCommentIface;
import cst.neu.yuejian_31.iface.AddMasterCommentListener;
import cst.neu.yuejian_31.service.AddMasterCommentService;
import cst.neu.yuejian_31.Common.Constant;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by xxe on 2017/10/24.
 */

public class AddMasterCommentModel implements AddMasterCommentIface {
    private Retrofit retrofit;
    public AddMasterCommentModel(){
        retrofit=new Retrofit.Builder()
                .baseUrl(Constant.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    @Override
    public void addmasterComment(String masterId, String userId, String mastercommentText, final AddMasterCommentListener addMasterCommentListener) {
        AddMasterCommentService addmatserCommentService=retrofit.create(AddMasterCommentService.class);
        Call<AddMasterCommentBean>call=
                addmatserCommentService.addMasterComment(masterId,userId,mastercommentText);
        call.enqueue(new Callback<AddMasterCommentBean>() {
            @Override
            public void onResponse(Call<AddMasterCommentBean> call, Response<AddMasterCommentBean> response) {
                if(response.isSuccessful()&&response.body()!=null){
                    addMasterCommentListener.onSuccess(response.body());

                }else {
                    addMasterCommentListener.onFail("Fail");
                }
            }

            @Override
            public void onFailure(Call<AddMasterCommentBean> call, Throwable t) {
                addMasterCommentListener.onFail(t.toString());

            }
        });
    }
}
